<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="scoreId">
        <el-input v-model="queryParams.scoreId" placeholder="请输入信息ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="征信机构用户ID" prop="creUserid">
        <el-input v-model="queryParams.creUserid" placeholder="请输入征信机构用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item -->
      <el-form-item label="企业名称">
        <el-input v-model="queryParams['comUser.comUsername']" placeholder="请输入企业名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--  <el-form-item label="企业信誉度" prop="corCre">
        <el-input v-model="queryParams.corCre" placeholder="请输入企业信誉度" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同履约情况" prop="conPer">
        <el-input v-model="queryParams.conPer" placeholder="请输入合同履约情况" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生产周期" prop="proCyc">
        <el-input v-model="queryParams.proCyc" placeholder="请输入生产周期" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生产风险" prop="proRis">
        <el-input v-model="queryParams.proRis" placeholder="请输入生产风险" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生产成本" prop="proCos">
        <el-input v-model="queryParams.proCos" placeholder="请输入生产成本" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="企业规模" prop="comSize">
        <el-input v-model="queryParams.comSize" placeholder="请输入企业规模" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="企业管理状况" prop="comSta">
        <el-input v-model="queryParams.comSta" placeholder="请输入企业管理状况" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="技术创新能力" prop="comTech">
        <el-input v-model="queryParams.comTech" placeholder="请输入技术创新能力" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="依法纳税情况" prop="comTax">
        <el-input v-model="queryParams.comTax" placeholder="请输入依法纳税情况" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="环境保护情况" prop="comEnv">
        <el-input v-model="queryParams.comEnv" placeholder="请输入环境保护情况" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="社会公益情况" prop="comSoc">
        <el-input v-model="queryParams.comSoc" placeholder="请输入社会公益情况" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择信息状态" clearable>
          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="哈希地址" prop="scoreHashaddr">
        <el-input v-model="queryParams.scoreHashaddr" placeholder="请输入哈希地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:scoring:add', 'truth:comhome:list']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:scoring:edit', 'truth:comhome:list']">修改</el-button>
      </el-col>
      <!--  <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:scoring:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:scoring:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scoringList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="scoreId" />
      <!--  <el-table-column label="征信机构用户id" align="center" prop="creUserid" /> -->
      <el-table-column label="企业ID" align="center" prop="comUserid" />
      <el-table-column label="企业信誉度" align="center" prop="corCre" />
      <el-table-column label="合同履约情况" align="center" prop="conPer" />
      <el-table-column label="生产周期" align="center" prop="proCyc" />
      <el-table-column label="生产风险" align="center" prop="proRis" />
      <el-table-column label="生产成本" align="center" prop="proCos" />
      <el-table-column label="企业规模" align="center" prop="comSize" />
      <el-table-column label="企业管理状况" align="center" prop="comSta" />
      <el-table-column label="技术创新能力" align="center" prop="comTech" />
      <el-table-column label="依法纳税情况" align="center" prop="comTax" />
      <el-table-column label="环境保护情况" align="center" prop="comEnv" />
      <el-table-column label="社会公益情况" align="center" prop="comSoc" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="哈希地址" align="center" prop="scoreHashaddr" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:scoring:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:scoring:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改定性信息评分对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules">
        <!--  <el-form-item label="征信机构用户id" prop="creUserid">
          <el-input v-model="form.creUserid" placeholder="请输入征信机构用户id" />
        </el-form-item> -->
        <el-form-item label="企业名称">
          <el-select v-model="form.comUserid" placeholder="请选择企业名称" clearable>
            <el-option v-for="item in comuserlist" :key="item.comUserid" :label="item.comUsername"
              :value="item.comUserid" />
          </el-select>
        </el-form-item>
        <el-form-item label="企业信誉度" prop="corCre">
          <el-input v-model="form.corCre" placeholder="请输入企业信誉度得分" />
        </el-form-item>
        <el-form-item label="合同履约情况" prop="conPer">
          <el-input v-model="form.conPer" placeholder="请输入合同履约情况得分" />
        </el-form-item>
        <el-form-item label="生产周期" prop="proCyc">
          <el-input v-model="form.proCyc" placeholder="请输入生产周期得分" />
        </el-form-item>
        <el-form-item label="生产风险" prop="proRis">
          <el-input v-model="form.proRis" placeholder="请输入生产风险得分" />
        </el-form-item>
        <el-form-item label="生产成本" prop="proCos">
          <el-input v-model="form.proCos" placeholder="请输入生产成本得分" />
        </el-form-item>
        <el-form-item label="企业规模" prop="comSize">
          <el-input v-model="form.comSize" placeholder="请输入企业规模得分" />
        </el-form-item>
        <el-form-item label="企业管理状况" prop="comSta">
          <el-input v-model="form.comSta" placeholder="请输入企业管理状况得分" />
        </el-form-item>
        <el-form-item label="技术创新能力" prop="comTech">
          <el-input v-model="form.comTech" placeholder="请输入技术创新能力得分" />
        </el-form-item>
        <el-form-item label="依法纳税情况" prop="comTax">
          <el-input v-model="form.comTax" placeholder="请输入依法纳税情况得分" />
        </el-form-item>
        <el-form-item label="环境保护情况" prop="comEnv">
          <el-input v-model="form.comEnv" placeholder="请输入环境保护情况得分" />
        </el-form-item>
        <el-form-item label="社会公益情况" prop="comSoc">
          <el-input v-model="form.comSoc" placeholder="请输入社会公益情况得分" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{ dict.label
            }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--  <el-form-item label="哈希地址" prop="scoreHashaddr">
          <el-input v-model="form.scoreHashaddr" placeholder="请输入哈希地址" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScoring, getScoring, delScoring, addScoring, updateScoring } from "@/api/truth/scoring";
import { listComhome } from "@/api/truth/comhome";
export default {
  name: "Scoring",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定性信息评分表格数据
      scoringList: [],
      //企业信息
      comuserlist: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 哈希地址时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scoreId: null,
        creUserid: null,
        comUserid: null,
        corCre: null,
        conPer: null,
        proCyc: null,
        proRis: null,
        proCos: null,
        comSize: null,
        comSta: null,
        comTech: null,
        comTax: null,
        comEnv: null,
        comSoc: null,
        status: null,
        createTime: null,
        scoreHashaddr: null,
        'comUser.comUsername': null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getcomuserList();
  },
  methods: {
    /** 查询定性信息评分列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listScoring(this.queryParams).then(response => {
        this.scoringList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getcomuserList() {
      listComhome().then(response => {
        this.comuserlist = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        scoreId: null,
        creUserid: null,
        comUserid: null,
        corCre: null,
        conPer: null,
        proCyc: null,
        proRis: null,
        proCos: null,
        comSize: null,
        comSta: null,
        comTech: null,
        comTax: null,
        comEnv: null,
        comSoc: null,
        status: null,
        createBy: null,
        createTime: null,
        scoreHashaddr: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.scoreId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加定性信息评分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const scoreId = row.scoreId || this.ids
      getScoring(scoreId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改定性信息评分";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.scoreId != null) {
            updateScoring(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScoring(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const scoreIds = row.scoreId || this.ids;
      this.$modal.confirm('是否确认删除定性信息评分编号为"' + scoreIds + '"的数据项？').then(function () {
        return delScoring(scoreIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/scoring/export', {
        ...this.queryParams
      }, `scoring_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
@import url('../../../../theme/dialog.css');
</style>
